<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_ACTION_PATH."base_action_class.php");
    require_once(CUTEENGINE_BASE_STEP_PATH."base_step_class.php");
	//
    // t_action_list_from_db
    //
	class t_action_list_from_db extends t_base_action
	{
        // property declaration
		// G
		const language_position_last = 1;
        

		// property declaration
		// public
		// P
        const proper_properties_position_per_SQL = 0;
        const proper_properties_position_last = 1;
        // R
        const required_fields_count = 4;
        // method declaration
    	// protected
        // G
		static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			/*switch ($a_index) 
            {
				case self::proper_properties_position_per_:
					$local_return = '';
				break;				
			}*/
			return $local_return;
		}
        protected function get_proper_properties_position_last()
        {
            return self::proper_properties_position_last;
        }
		protected function get_required_fields_count()
        {
            return self::required_fields_count;
        }
        

		// I
        protected function initialize_action()
        {		

			if (! $this->initialized)
			{
                parent::initialize_action();

			}
			return $this->initialized;
		}		
        protected function initialize_step_execution()
        {		

			$local_step = $this->steps_list[$this->current_step_index];
			$local_index = $this->current_step_index;
			$local_step->initialize();
			if ($local_index === 0)
			{
				$this->custom_execute_step($local_step);                        
				
				
			}    
			else
			{
				$this->execute_step($local_step);                                            
			}
		}	
        protected function custom_execute_step($a_step)        
        {
            $local_next_step = $this->steps_list[$this->current_step_index + 1];
			$local_field = $a_step->field;
            $local_tag = $local_field->get_start_tag();
            $local_class = get_class($a_step);
            switch ($local_class) 
            {
                /*********** t_step_set_ce_field_event ***********/
                case t_step_set_ce_field_event:
					$local_field->add_event($this->get_event_type(), $this->get_event_name(),
						$this->get_content_loader_code($local_next_step->code,true,true));
                    
                break;		
            }
        }
        // method declaration
    	// public
        public function __construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str) 
		{
            parent::__construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str);
          //  echo "count:".count($this->fields_list);
			// steps
            $this->steps_list[t_base_action::step_start] = t_base_step::create_step_from_string('|t_step_set_ce_field_event|'.$this->get_action_name().'_get|'.
              $this->fields_list[t_base_action::step_start].'|'); 
            //$this->steps_list[t_base_action::step_start] = t_base_step::create_step_from_string('|t_step_ajax_get|'.$this->get_action_name().'_get|'.
              //$this->fields_list[t_base_action::step_start].'|'); 
            $this->steps_list[t_base_action::step_criteria] = t_base_step::create_step_from_string('|t_step_ajax_display|'.$this->get_action_name().'_list|'.
              $this->fields_list[t_base_action::step_criteria].'|'); 
			$this->steps_list[t_base_action::step_result] = t_base_step::create_step_from_string('|t_step_ajax_put|'.$this->get_action_name().'_res|'.
              $this->fields_list[t_base_action::step_result].'|');   
            if ($this->fields_list[3] != '')
            {
                $this->steps_list[3] = t_base_step::create_step_from_string('|t_step_set_html_tag_property|'.$this->get_action_name().'_finalize|'.
                    $this->fields_list[3].'|disabled|false|'); 
            }        
			
		}
        // D
		public function do_action_from_ajax()
        {
			global $g_ambient_namespace;
			$local_result = new t_content_loader_result;
            $local_result_step = $this->steps_list[t_base_action::step_result];
			$local_result_field = $local_result_step->field; 
            $local_parameter = parent::do_action_from_ajax();
			
			$local_select_location_query = $this->get_action_name()."_query";
			$local_component = $this->parent_component;
			//echo $this->proper_properties_array[self::proper_properties_position_per_SQL];
			$local_component->new_query(
				$local_select_location_query,
				$this->proper_properties_array[self::proper_properties_position_per_SQL],
				$g_ambient_namespace->connection);
			//
			$local_query_query = $local_component->get_query(
				$local_select_location_query);
			$local_query_query->set_value_parameter(
				$local_parameter->get_argument_value(2),0);
			//print_r($local_parameter);
			//echo "PARAM 2: '".$local_parameter->get_argument_value(2). "' - SQL NO PARAM: ".$local_query_query->sql_str ." - SQL". $local_query_query->retrive_sql_query_with_value_parameter($local_query_query->sql_str)."<br>"; 
		    $local_destination_tag_name = $local_parameter->get_argument_value(3);
			//echo "local_destination_tag_name:$local_destination_tag_name<br>"; 
			// manage result
			
			$local_query_query->execute_function_from_query_result ($local_result_field,
				'get_tags_list_structure',Array($local_result,$local_destination_tag_name));
			if (($local_query_query->query_num_rows() == 0) &&
				(method_exists($local_result_field,'get_tags_list_structure_from_empty_query')))
				$local_string_result = $local_result_field->get_tags_list_structure_from_empty_query(Array($local_result,$local_destination_tag_name));	
							
            echo $local_result->get_json_string();
            
        }
        //G
		public function get_event_name()
        {	
			$local_result_step = $this->steps_list[t_base_action::step_result];
			$local_result_field = $local_result_step->field; 
            return $local_result_field->get_event_name(t_base_field::field_event_type_on_edit);
			
		}
        
        public function get_event_type()
        {	
			return t_base_field::field_event_type_on_edit;
			
		} 
		// G
        public function get_language_position_last()
        {
            return self::language_position_last;
        }
		
        
    }
?>    